﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Utils;
//one user 
namespace UI.ModSalary
{
    public partial class SalaryYearAdd : System.Web.UI.Page
    {
        SalaryYearBiz salaryYearBiz = new SalaryYearBiz();
       static  string salId = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["SalId"] != null)
            {
                salId = Request.Params["SalId"].ToString();              
            }
            if (!IsPostBack)
            {
                if (!string.IsNullOrWhiteSpace(salId))
                    DataBond(salId);
            }

        }
        private void DataBond(string salId)
        {
            DataTable dt = salaryYearBiz.GetYearEnd(salId);
            if (dt.Rows.Count > 0)
            {
                txtEmpCode.Text = dt.Rows[0]["EmpCode"].ToString();
                txtEmpCode.ReadOnly = true;
                txtDeptName.Text = dt.Rows[0]["DeptName"].ToString();
                txtDutyName.Text = dt.Rows[0]["DutyName"].ToString();
                txtEmpName.Text = dt.Rows[0]["EmpName"].ToString();
                txtJoinTime.Text = dt.Rows[0]["JoinTime"].ToString();
                txtMemo.Text = dt.Rows[0]["Memo"].ToString();
                txtn01k.Text = dt.Rows[0]["n01k"].ToString();
                txtn02k.Text = dt.Rows[0]["n02k"].ToString();
                txtn03k.Text = dt.Rows[0]["n03k"].ToString();
                txtn11k.Text = dt.Rows[0]["n11k"].ToString();
                txtn20k.Text = dt.Rows[0]["n20k"].ToString();
                txtn21k.Text = dt.Rows[0]["n21k"].ToString();
                txtn22k.Text = dt.Rows[0]["n22k"].ToString();
                txtn23k.Text = dt.Rows[0]["n23k"].ToString();
                txtn31k.Text = dt.Rows[0]["n31k"].ToString();
                txtSalaryAccount.Text = dt.Rows[0]["SalaryAccount"].ToString();
                txtSalYear.Text = dt.Rows[0]["SalYear"].ToString();
                txtSalYear.ReadOnly = true;
                txtStateName.Text = dt.Rows[0]["StateName"].ToString();
                txtWorkMonthInYear.Text = dt.Rows[0]["WorkMonthInYear"].ToString();
                txtZipCode.Text = dt.Rows[0]["ZipCode"].ToString();            
            
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string empCode = txtEmpCode.Text.Trim();
            if (string.IsNullOrWhiteSpace(empCode))
            {
                JSUtility.Alert(this, "工号不能为空！");
                return;
            }
            string salYear = txtSalYear.Text.Trim();
            if (salaryYearBiz.IsExist(salYear, empCode,"1"))
            {
                JSUtility.Alert(this,"已经存在改员工的年终奖！");
                return;
            }
            SortedDictionary<string, string> sdList = new SortedDictionary<string, string>();
            sdList.Add("EmpCode", empCode);
            //sdList.Add("DeptName", txtDeptName.Text.Trim());
            //sdList.Add("DutyName", txtDutyName.Text.Trim());
            //sdList.Add("EmpName", txtEmpName.Text.Trim());
            //sdList.Add("JoinTime", txtJoinTime.Text.Trim());
            sdList.Add("Memo", txtMemo.Text.Trim());
            sdList.Add("n01k", txtn01k.Text.Trim());
            sdList.Add("n02k", txtn02k.Text.Trim());
            sdList.Add("n03k", txtn03k.Text.Trim());
            sdList.Add("n11k", txtn11k.Text.Trim());
            sdList.Add("n20k", txtn20k.Text.Trim());
            sdList.Add("n21k", txtn21k.Text.Trim());
            sdList.Add("n22k", txtn22k.Text.Trim());
            sdList.Add("n23k", txtn23k.Text.Trim());
            sdList.Add("n31k", txtn31k.Text.Trim());
             //sdList.Add("", txtSalaryAccount.Text.Trim());
            sdList.Add("SalYear", txtSalYear.Text.Trim());
             //sdList.Add("", txtStateName.Text.Trim());
            sdList.Add("WorkMonthInYear", txtWorkMonthInYear.Text.Trim());
            //sdList.Add("",  txtZipCode.Text.Trim());

            if (new SalaryTableBiz().Insert("Wage_SalaryListYear", sdList))
            {
                JSUtility.Alert(this, "增加成功");
            }
            else
                JSUtility.Alert(this, "增加失败");
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string empCode = txtEmpCode.Text.Trim();
            if (string.IsNullOrWhiteSpace(empCode))
            {
                JSUtility.Alert(this, "工号不能为空！");
                return;
            }
            string salYear = txtSalYear.Text.Trim();
            
            SortedDictionary<string, string> sdList = new SortedDictionary<string, string>();
            sdList.Add("SalId", salId);
            sdList.Add("EmpCode", empCode);           
            sdList.Add("Memo", txtMemo.Text.Trim());
            sdList.Add("n01k", txtn01k.Text.Trim());
            sdList.Add("n02k", txtn02k.Text.Trim());
            sdList.Add("n03k", txtn03k.Text.Trim());
            sdList.Add("n11k", txtn11k.Text.Trim());
            sdList.Add("n20k", txtn20k.Text.Trim());
            sdList.Add("n21k", txtn21k.Text.Trim());
            sdList.Add("n22k", txtn22k.Text.Trim());
            sdList.Add("n23k", txtn23k.Text.Trim());
            sdList.Add("n31k", txtn31k.Text.Trim());
           
            sdList.Add("SalYear", txtSalYear.Text.Trim());           
            sdList.Add("WorkMonthInYear", txtWorkMonthInYear.Text.Trim());

            if (new SalaryTableBiz().Update("Wage_SalaryListYear", sdList))
            {
                JSUtility.Alert(this, "更新成功");
            }
            else
                JSUtility.Alert(this, "更新失败");
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            string[] sdList = new string[] { "SalId",salId, "N" };
            string info = new SalaryTableBiz().Delete("Wage_SalaryListYear", sdList);
            JSUtility.Alert(this, info);
        }

        protected void btnClose_Click(object sender, EventArgs e)
        {
            JSUtility.CloseWindow();
        }
    }
}